home *** CD-ROM | disk | FTP | other *** search
- /* ferror.c */
- #include <stdio.h>
- char buffer[81] = "This will not be written";
- main()
- {
- FILE *infile;
- /* Open the file "c:\autoexec.bat". Note the two '\' */
- if ((infile = fopen("c:\\autoexec.bat", "r")) == NULL)
- {
- perror ("fopen failed.\n");
- exit(0);
- }
- fprintf(infile, "%s\n", buffer);
- if (ferror(infile) != 0) /* Check for error */
- {
- printf("Error detected\n");
- clearerr(infile); /* Now clear the error */
- printf("Error cleared\n");
- }
- }